<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$title}-{$Think.lang.web_name}</title>
    {include file="comm/header"/}
</head>
<body>
{include file="comm/left_menu"/}
{include file="comm/top_menu"/}
<div class="container main">
    <div class="col-sm-12 border-bottom text-right"><a class="btn btn-primary mgr-10" href="/Models/model_list/id/{$model._model_id}"><i class="fa fa-list-ul"></i>&nbsp;{$Think.lang.model_list}</a></div>

    <div class="col-sm-12">
        <div class="col-sm-12"> &nbsp;</div>
        <form class="form-horizontal" method="post" action="/Models/model_save/">

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.model_name}</label>
                <div class="col-sm-3">
                    <input class="form-control" name="model_name" value="{$model.model_name}" required>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.model_table}</label>
                <div class="col-sm-3">
                    <select class="form-control" name="model_field_id">
                        <option value="0">{$Think.lang.select}</option>
                        {if isset($model_field_list)}
                        {foreach name="$model_field_list" key="key" id="v" index="i"}
                        <option value="{$v.field_id}" {if in_array($v.field_id,[$model.model_field_id])} selected{/if}>{$v.field_name}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
                <small class="col-sm-4 form-tips">{$Think.lang.select}是不更新字段信息（初次选择除外）</small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">{$Think.lang.model_action}</label>
                <div class="col-sm-3">
                    <select class="form-control" name="model_action">
                        <option value="0">{$Think.lang.select}</option>
                        {foreach name="$menu_list" key="key" id="v" index="i"}
                        <option value="{$v.menu_name}" {if in_array($v.menu_name,[$model.model_action])} selected{/if}>{$v.add_str|raw}{$v.menu_title}</option>
                        {/foreach}

                    </select>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label" style="font-family: '宋体',sans-serif;">选择下面字段</label>

                <small class="col-sm-1 form-tips"></small>
            </div>
            {foreach name="model_fields" key="key" id="v" index="i"}
            <div class="form-group" style="margin-bottom:0.3em;">
                <label class="col-sm-3 control-label">{$v.field_desc}</label>
                <div class="col-sm-3">
                    <input type="hidden" name="fields[{$key}][field_pid]" value="{$v.field_pid}">
                    <input type="hidden" name="fields[{$key}][field_name]" value="{$v.field_name}">
                    <input type="hidden" name="fields[{$key}][field_desc]" value="{$v.field_desc}">
                    <input class="form-control" name="fields[{$key}][field_alias]"  value="{$v.field_alias}"  placeholder="字段别名说明">
                </div>
                <small class="col-sm-4 form-tips">
                    <label class="s-label-checkbox">
                        <input type="checkbox" name="fields[{$key}][checked]" value="1" id="checked{$i}" {if in_array($v.checked,[1])} checked {/if}>
                        <label for="checked{$i}" class="fa fa-check"></label>
                    </label>
                </small>
            </div>
            {/foreach}
            <div class="form-group" style="margin-bottom: 4em;margin-top: 1em;">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-7">
                    <a href="javascript:all_select();" class="btn btn-primary" style="margin-right: 2em;">全选</a>
                    <a href="javascript:not_all_select();" class="btn btn-primary">全不选</a>
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-3 control-label"></label>
                <div class="col-sm-3">
                    <input type="hidden" name="model_id" value="{$model.model_id}">
                    <input type="hidden" name="token" value="">
                    <button class="btn btn-primary" type="submit">提交保存</button>
                </div>
                <small class="col-sm-4 form-tips"></small>
            </div>

        </form>
    </div>
</div>
{include file="comm/footer"/}
<script type="text/javascript">
    function all_select() {
        var checked = $("input[name*='[checked]']");
        for (var i=0,len=checked.length;i<len;i++){
            checked[i].checked = true;
        }
    }
    function not_all_select() {
        var checked = $("input[name*='[checked]']");
        //$("input[name='group_rules[]']").removeAttr("checked");
        //$("input[name='group_rules[]']").attr("checked",false);
        for (var i=0,len=checked.length;i<len;i++){
            checked[i].checked = false;
        }
    }

</script>
</body>
</html>